﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace CoreLib.MySQL
{
    public class DbCreator : DbBaseQuery<DbCreator>, IDbQuery
    {
        private DbProvider dbProvider;
        private string name;

        public DbCreator(DbProvider dbProvider)
        {
            this.dbProvider = dbProvider;
            base.TQuery = this;
        }

        public void SetName(string name)
        {
            this.name = name;
        }

        public void Execute()
        {
            using (MySqlConnection connection = dbProvider.CreateMySqlConnection())
            {
                using (MySqlCommand cmd = new MySqlCommand(string.Format("CREATE DATABASE IF NOT EXISTS {0}", this.name), connection))
                {
                    cmd.ExecuteNonQuery();
                }
            }
        }
    }
}
